package com.gaoxin.api.contronller.stucontroller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.gaoxin.api.entity.statisentity.StudentInfo;
import com.gaoxin.api.service.stuservice.QueryStuCourseService;
import com.google.common.collect.Maps;

/**
 * 查询学生的所有课程controller
 * 
 * @author zhaozhenshe 2018-08-02
 */
@RestController
@RequestMapping("app/student")
public class QueryStuCourseController {
	@Autowired
	private QueryStuCourseService queryStuCourseService;

	/**
	 * 根据学号、学年学期查询学生的课程
	 * 
	 * @return
	 */
	@RequestMapping(value = "/queryStuCourse", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	public String queryStudentCourse(@RequestBody Map<String, String> paramMap) {
		String stuNumber = paramMap.get("stuNumber");
		String[] paramArr = paramMap.get("semester").split("_");
		String year = "";
		String term = "";
		if (!"".equals(paramMap.get("semester"))) {
			year = paramArr[0];
			term = paramArr[1];
		}
		Map<String, Object> map = Maps.newHashMap();
		String jsonData = null;
		try {
			StudentInfo studentInfo = queryStuCourseService.findStuCourse(stuNumber, year, term);
			if (studentInfo != null) {
				map.put("code", "0");
				map.put("results", studentInfo);
				jsonData = JSON.toJSONString(map);
			} else {
				map.put("code", "100103");
				map.put("errmsg", "无法查询到该学生对应的课程信息！");
				jsonData = JSON.toJSONString(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonData;
	}
}
